<template>
    <div class="main">
        <!-- 导航栏 -->
        <div>
            <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item>录取信息管理></el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <!-- 表格 -->
        <div>
            <el-card class="box-card">
                <el-row>
                    <el-col :span="3">
                        <el-colomun style="float:left;margin-right:10px;">
                            <el-upload
                            class="upload-demo"
                            action="http://taruinfo.work:8088/Matriculate/excelImport"
                            :on-preview="handlePreview"
                            :on-remove="handleRemove"
                            :before-remove="beforeRemove"
                            multiple
                            :limit="1"
                            :on-exceed="handleExceed"
                            :file-list="fileList">
                            <el-button  type="primary">信息导入</el-button>
                            </el-upload>
                        </el-colomun>
                    </el-col>
                    <el-col :span="5">
                        <el-select v-model="value" style="width:135px" placeholder="请选择">
                            <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                        <el-input v-model="value2" style="width:100px;margin-left:10px"></el-input>
                    </el-col>
                    <el-col :span="4">
                        <el-button @click="mohuchaxun()" type="success">查询</el-button>
                        <el-button @click="chongzhi()" type="success">重置</el-button>
                    </el-col>
                    <el-col :span="9">
                        <el-input v-model="value3" placeholder="请输入班级" style="width:200px;margin-left:10px"></el-input>
                        <el-select v-model="value4" style="width:135px" placeholder="请选择">
                            <el-option
                            v-for="item in options2"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="1">
                        <el-button @click="daochu()" type="success">导出</el-button>
                    </el-col>
                </el-row>
                <el-row style="margin-top:30px">
                    <el-col :span="24">
                        <el-table
                :data="tableData"
                height="450px"
                stripe
                style="width: 100%">
                <el-table-column
                type="index"
                >
                </el-table-column>
                <el-table-column
                prop="studentId"
                show-overflow-tooltip
                label="学号">
                </el-table-column>
                <el-table-column
                prop="name"
                label="姓名">
                </el-table-column>
                <el-table-column
                prop="sex"
                label="性别">
                </el-table-column>
                <el-table-column
                prop="candidateId"
                show-overflow-tooltip
                label="身份证号">
                </el-table-column>
                <el-table-column
                prop="facultyName"
                label="学院">
                </el-table-column>
                <el-table-column
                prop="specialtyName"
                show-overflow-tooltip
                label="专业">
                </el-table-column>
                <el-table-column
                prop="className"
                show-overflow-tooltip
                label="班级">
                </el-table-column>
                <el-table-column
                prop="province"
                show-overflow-tooltip
                label="省份">
                </el-table-column>
                <el-table-column
                prop="notificationNumber"
                show-overflow-tooltip
                label="录取编号">
                </el-table-column>
                <el-table-column
                prop="candidateId"
                show-overflow-tooltip
                label="准考证号">
                </el-table-column>
                <el-table-column
                prop="timestamp"
                show-overflow-tooltip
                label="时间">
                </el-table-column>
                <el-table-column
                prop="address"
                label="操作">
                <template slot-scope="scope">
                    <el-button @click="editData(scope.row)" type="text" size="small">编辑</el-button>
                    <el-button @click="deleteData(scope.row)" type="text" size="small">删除</el-button>
                </template>
                </el-table-column>
                        </el-table>
                    </el-col>
                </el-row>
                <!-- <div>
                    <div style="float:left;margin-top:10px">
                        
                        
                    </div>
                    <div style="margin-top:30px">
                        
                    </div>  
                </div> -->
            <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="count"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
            </el-pagination>
            </el-card>
            <el-dialog
            title="编辑"
            :visible.sync="centerDialogVisible"
            width="45%"
            height="450px"
            center>
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="学号">
                    <el-input v-model="form.studentId" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="姓名">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>
                <el-form-item label="性别">
                    <el-input v-model="form.sex" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="身份证号">
                    <el-input v-model="form.idCard"></el-input>
                </el-form-item>
                <el-form-item label="学院">
                    <el-input v-model="form.facultyName"></el-input>
                </el-form-item>
                <el-form-item label="专业">
                    <el-input v-model="form.specialtyName"></el-input>
                </el-form-item>
                <el-form-item label="班级">
                    <el-input v-model="form.className"></el-input>
                </el-form-item>
                <el-form-item label="省份">
                    <el-input v-model="form.province"></el-input>
                </el-form-item>
                <el-form-item label="录取编号">
                    <el-input v-model="form.notificationNumber" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="准考证号">
                    <el-input v-model="form.candidateId" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="报道时间">
                    <el-input v-model="form.timestamp" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="是否报道">
                    <el-select v-model="form.reportInfo" placeholder="请选择">
                    <el-option label="已报到" value="是"></el-option>
                    <el-option label="未报到" value="否"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="centerDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="commitData()">提交</el-button>
            </span>
            </el-dialog>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{
            tableData:[],
            total:10,
            page:1,
            count:10,
            centerDialogVisible:false,
            form:{},
            fileList:[],
            options:[
                {value:'0',label:'姓名'},
                {value:'1',label:'学号'},
                {value:'2',label:'身份证号'},
            ],
            options2:[
                {value:'是',label:'是'},
                {value:'否',label:'否'}
            ],
            value:'',
            value2:'',
            value3:'',
            value4:''
        }
    },
    methods:{
         getData(){
            var _this=this
            var url='http://taruinfo.work:8088/selectMatriculateByPage?page='+_this.page+'&pageCount='+_this.count
            _this.$axios.get(url).then(function(res){
                console.log(res.data)
                if(res.data !=''){
                  _this.total=res.data.total
                  _this.tableData=res.data.records
                }else{
                    console.log('获取宿舍信息失败')
                }
            })
        },
        handleSizeChange(val){
            this.count=val
            this.getData()
        },
        handleCurrentChange(val){
            this.page=val
            this.getData()
        },
        editData(row) {
            console.log(row)
            this.form=row
            this.centerDialogVisible=true
        },
        commitData(){
            var _this=this
            var url='http://taruinfo.work:8088/UpdateMatriculate'
            _this.$axios.put(url,_this.form).then(function(res){
                if(res.data.code==200){
                    _this.$message({
                      message: '更新成功',
                      type: 'success'
                    })
                    _this.centerDialogVisible=false
                    _this.getData()
                }else{
                   _this.$message({
                      message: '更新失败',
                      type: 'error'
                    })
                   _this.centerDialogVisible=false 
                }
            })
        },

        deleteData(row){
            var _this=this
            var url='http://taruinfo.work:8088/deleteByMatriculate?id='+row.id
            _this.$confirm('此操作将永久删除该信息, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
                _this.$axios.delete(url).then(function(res){
                if(res.data.code==200){
                    _this.$message({
                        type: 'success',
                        message: '删除成功!'
                    })
                    _this.getData()
                }else{
                    _this.$message({
                        type: 'error',
                        message: '删除失败!'
                    })
                }
            })  
            }).catch(() => {
                _this.$message({
                    type: 'info',
                    message: '已取消删除'
                })         
            })
        console.log(row)
        },
        chongzhi(){
            this.getData()
        },
        mohuchaxun(){
            var _this=this
            var url1='http://taruinfo.work:8088/likeMatriculateByLists?current=1&name='+_this.value2+'&size=10'
            var url2='http://taruinfo.work:8088/likeMatriculateByLists?current=1&size=10&studentId='+_this.value2
            var url3='http://taruinfo.work:8088/likeMatriculateByLists?current=1&idCard='+_this.value2+'&size=10'
            if(_this.value2!=''){
                if(_this.value=='0'){
                    _this.$axios.get(url1).then(function(res){
                    console.log(res.data)
                    if(res.data.code =='200'){
                    _this.total=res.data.data.total
                    _this.tableData=res.data.data.records
                    _this.value=''
                    _this.value2=''
                    }else{
                        console.log('获取宿舍信息失败')
                    }
                })
                }else if(_this.value=='1'){
                    _this.$axios.get(url2).then(function(res){
                    console.log(res.data)
                    if(res.data.code =='200'){
                    _this.total=res.data.data.total
                    _this.tableData=res.data.data.records
                    _this.value=''
                    _this.value2=''
                    }else{
                        console.log('获取宿舍信息失败')
                    }
                })
                }else if(_this.value=='2'){
                    _this.$axios.get(url3).then(function(res){
                    console.log(res.data)
                    if(res.data.code =='200'){
                    _this.total=res.data.data.total
                    _this.tableData=res.data.data.records
                    _this.value=''
                    _this.value2=''
                    }else{
                        console.log('获取宿舍信息失败')
                    }
                })
                }else{

                }
            }else{
                _this.$message({
                    message: '条件不能为空',
                    type: 'warning'
                })
            }
        },
        handleRemove(file, fileList) {
            console.log(file, fileList);
        },
        handlePreview(file) {
            console.log(file);
        },
        handleExceed(files, fileList) {
            this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
        },
        daochu(){
            var _this=this
            var url='http://taruinfo.work:8088/Matriculate/Export?className='+_this.value3+'&fileName='+_this.value3+'名单&reportinfo='+_this.value4
            if(_this.value3==''||_this.value4==""){
                _this.$message({
                    message:'条件不能为空',
                    type:'warning'
                })
            }else{
                _this.$message({
                    message: '导出成功',
                    type: 'success'
                })
                window.location.href=url
                _this.value3=''
                _this.value4=''
            }
        }
    },
    mounted(){

    },
    created(){
        this.getData()
    }
}
</script>

<style scoped>
.box-card{
    width: 1270px;
    height:615px;
    margin-top: 10px;
}
</style>